import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '@/views/login/login'
import admin_home from '@/views/admin/Home.vue'
import admin_index from '@/views/admin/Index.vue'
import admin_menu from '@/views/admin/menu/Menu.vue'
import admin_role from '@/views/admin/menu/Role.vue'
import admin_role_menu from '@/views/admin/menu/RoleMenu.vue'
import admin_dept from '@/views/admin/student/Dept.vue'
import admin_classes from '@/views/admin/student/Classes.vue'
import admin_grade from '@/views/admin/student/Grade.vue'
import admin_major from '@/views/admin/student/Major.vue'
import admin_user from '@/views/admin/menu/User.vue'
import admin_unit from '@/views/admin/flag/Unit.vue'
import admin_user_detail from '@/views/admin/menu/UserDetail.vue'
import admin_user_role from '@/views/admin/menu/UserRole.vue'
import admin_unit_detail from '@/views/admin/flag/Member.vue'
import admin_clothing from '@/views/admin/flag/Clothing.vue'
import admin_equipment from '@/views/admin/flag/Equipment.vue'
import admin_userinfo from '@/views/admin/flag/UserInfo.vue'
import Cookie from 'js-cookie'
Vue.use(VueRouter)
const routes = [
	{ path: "/",redirect:"/admin/home/index"},
	{ path: "/login", component: login,meta:{requireAuth:false}},
    {path: '/admin/home', component: admin_home, meta: { requireAuth: true }, redirect: '/admin/home/index', children: [
        { path: 'index', component: admin_index, meta: { requireAuth: true } },
        { path: 'menu', component: admin_menu, meta: { requireAuth: true } },
        { path: 'role', component: admin_role, meta: { requireAuth: true } },
        { path: 'roleMenu', component: admin_role_menu, meta: { requireAuth: true } },
        { path: 'dept', component: admin_dept, meta: { requireAuth: true } },
        { path: 'class', component: admin_classes, meta: { requireAuth: true } },
        { path: 'grade', component: admin_grade, meta: { requireAuth: true } },
        { path: 'major', component: admin_major, meta: { requireAuth: true } },
        { path: 'user', component: admin_user, meta: { requireAuth: true } },
        { path: 'unit', component: admin_unit, meta: { requireAuth: true } },
        { path: 'user/detail/:uid', component: admin_user_detail, meta: { requireAuth: true }, props: true },
        { path: 'userRole', component: admin_user_role, meta: { requireAuth: true } },
        { path: 'unit/:id', component: admin_unit_detail, meta: { requireAuth: true }, props: true },
        { path: 'clothing', component: admin_clothing, meta: { requireAuth: true } },
        { path: 'equipment', component: admin_equipment, meta: { requireAuth: true } },
        { path: 'userinfo', component: admin_userinfo, meta: { requireAuth: true } },
        
    ]}
]

const router = new VueRouter({
  routes
})

const loginPath = ['/login']

router.beforeEach((to, from, next) => {
    if (to.meta.requireAuth) {
        //需要权限认证的路由
        if (Cookie.get('token')) {
            //已登录
            next();
        } else {
            //未登录
            Vue.prototype.$message.error("未登录，请先登录")
            next("/login");
        }
    } else {
        //不需要权限认证的路由
        next();
    }
})




export default router
